<template>
  <div>
    <el-dialog
      :before-close="handleClose"
      :visible.sync="dialogVisible"
      title="选择菜单图标"
      :append-to-body="true"
      width="900px"
    >
      <div class="iconBox">
        <el-input
          ref="search"
          v-model="iconVal"
          placeholder="输入关键词搜索,注意全是英文"
          clearable
          style="width: 300px"
          @input="upIcon(iconVal)"
        />
        <div class="icons-container">
          <div class="grid">
            <div
              v-for="item of list"
              :key="item"
              @click="
                handleClipboard(generateElementIconCode(item), $event, item)
              "
              style="text-align: center;"
            >
              <el-tooltip placement="top">
                <div slot="content">
                  {{ generateElementIconCode(item) }}
                </div>
                <div class="icon-item">
                  <!-- <i :class="'el-icon-' + item" /> -->
                  <svg-icon
                    
                    :icon-class="item"
                  ></svg-icon>
                  <span>{{ item }}</span>
                </div>
              </el-tooltip>
            </div>
          </div>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { iconList } from "../options";
export default {
  data() {
    return {
      iconList,
      dialogVisible: false,
      list: [],
      iconVal: ""
    };
  },
  mounted() {
    this.list = iconList;
  },
  methods: {
    generateElementIconCode(symbol) {
      return `<i class="el-icon-${symbol}" />`;
    },
    handleClipboard(text, event, n) {
      this.iconChange(n);
      //  clipboard(text, event)
    },
    // 搜索
    upIcon(n) {
      const arrs = [];
      for (var i = 0; i < this.iconList.length; i++) {
        if (this.iconList[i].indexOf(n) !== -1) {
          arrs.push(this.iconList[i]);
          this.list = arrs;
        }
      }
    },
    iconChange(n) {
        console.log(n);
        
      this.$emit("getIcon", n);
      this.handleClose();
    },
    openlog() {
      this.dialogVisible = true;
    },
    handleClose() {
      this.dialogVisible = false;
    }
  }
};
</script>

<style lang="scss" scoped>
.iconBox{
    
}
.icons-container {
  margin: 10px 20px 0;
  overflow: hidden;
  height: 500px;
    overflow: auto;

  .grid {
    position: relative;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  }

  .icon-item {
    margin: 10px 20px;
    text-align: center;
    width: 100px;
    float: left;
    font-size: 30px;
    color: #24292e;
    cursor: pointer;
  }

  span {
    display: block;
    font-size: 16px;
    margin-top: 10px;
  }

  .disabled {
    pointer-events: none;
  }
}
</style>
